/// @description 控制
//作者:蟋蟀蝈蝈蛐蛐 QQ:1126390395

#region 人物移动逻辑

if(!run) //非运动进行判断
{
	run = true;
	image_speed = 0;
	
	//按键改变方向
	if(key_map[_DIR.right])
		dir = _DIR.right;
	else if(key_map[_DIR.left])
		dir = _DIR.left;
	else if(key_map[_DIR.up])
		dir = _DIR.up;
	else if(key_map[_DIR.down])
		dir = _DIR.down;
	else
		run = false;

	//阻挡判断
	var box = false;
	var bbox = false;
	switch(dir)
	{
		case _DIR.right:
			box = collision_point(x+32+16, y+16, oBoxFa, false, true);
			bbox = collision_point(x+32+16+32, y+16, oBoxFa, false, true);
		break;
	
		case _DIR.left:
			box = collision_point(x-16, y+16, oBoxFa, false, true);
			bbox = collision_point(x-16-32, y+16, oBoxFa, false, true);
		break;
	
		case _DIR.up:
			box = collision_point(x+16, y-16, oBoxFa, false, true);
			bbox = collision_point(x+16, y-16-32, oBoxFa, false, true);
		break;
	
		case _DIR.down:
			box = collision_point(x+16, y+32+16, oBoxFa, false, true);
			bbox = collision_point(x+16, y+32+16+32, oBoxFa, false, true);
		break;
	}

	//如果有阻挡，切换为推精灵
	if(box&&box.place==true)
	{
		push = true;
		push_box = box;
		push_bbox = bbox;
	}
	else
	{
		push = false;
		push_box = false;
	}
}
else //运动时进行行走
{
	image_speed = 1;
	switch(dir)
	{
		case _DIR.right:
			if(!push||(push&&push_box.push&&!push_bbox))
			{
				x += sp;
				if(push_box)
					push_box.x += sp;
			}
		break;
	
		case _DIR.left:
			if(!push||(push&&push_box.push&&!push_bbox))
			{
				x -= sp;
				if(push_box)
					push_box.x -= sp;
			}
		break;
	
		case _DIR.up:
			if(!push||(push&&push_box.push&&!push_bbox))
			{
				y -= sp;
				if(push_box)
					push_box.y -= sp;
			}
		break;
	
		case _DIR.down:
			if(!push||(push&&push_box.push&&!push_bbox))
			{
				y += sp;
				if(push_box)
					push_box.y += sp;
			}
		break;
	}
	
	//停下来
	if(x%32==0&&y%32==0)
	{
		push_box = false;
		run = false;
	}
}

#endregion

#region 精灵序列切换逻辑

//根据是否推选择精灵数组
var spr = spr_walk;
if(push)
	spr = spr_push;
	
//根据方向，选择具体的精灵
sprite_index = spr[dir];

//非移动，精灵固定第一帧
if(!run)
{
	image_index = 0;
}

#endregion

